/**
 * 北京中流科技有限公司 版权所有
 * http://www.chinasoa.com.cn
 */
package cn.com.chinasoa.course.subscribe.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

/**
 * @author 刘洋(liuyang@chinasoa.com.cn)
 * 2007-9-24上午10:54:43
 * 预订课程订单
 */
@Entity
public class SubscribeOrder implements Serializable {

	private static final long serialVersionUID = -2051948371463400027L;
	@Id
    @GeneratedValue(strategy=GenerationType.AUTO) 
	private long id;
	@Version
	private int version;
	//学员名称
	@Column(nullable=false)
	private String studentName;
	//学员身份证号
	@Column(nullable=false)
	private String studentIDCard;
	//学员邮件
	@Column(nullable=false)
	private String studentEmail;

	//学员性别,false=男,true=女
	@Column(nullable=false)
	private boolean studentSex=false;
	//学员电话
	@Column(nullable=false)
	private String studentPhone;
	//工作单位
	@Column(nullable=false)
	private String studentCompany;
	//学员地址
	@Column(nullable=false)
	private String studentAddress;
	//付款方式
	@Column(nullable=false)
	private String payMethod;

	//学员移动电话
	@Column(nullable=false)
	private String mobilePhone;

	//下单时间
	@Column(nullable=false)
	private Date subscribeDate=new Date();

	//订单处理的状态
	@Column(nullable=false)
	private String status;

	//计划实施的课程
	@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
	private ArrangedCourse arrangedCourse;

	@ManyToOne(cascade=CascadeType.REFRESH,optional=true,fetch=FetchType.EAGER)
	private PrivilegeStrategy privilegeStrategy;

	public ArrangedCourse getArrangedCourse() {
		return arrangedCourse;
	}
	public void setArrangedCourse(ArrangedCourse arrangedCourse) {
		this.arrangedCourse = arrangedCourse;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getMobilePhone() {
		return mobilePhone;
	}
	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}
	public String getStudentEmail() {
		return studentEmail;
	}
	public void setStudentEmail(String studentEmail) {
		this.studentEmail = studentEmail;
	}
	public String getStudentIDCard() {
		return studentIDCard;
	}
	public void setStudentIDCard(String studentIDCard) {
		this.studentIDCard = studentIDCard;
	}
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public int getVersion() {
		return version;
	}
	public void setVersion(int version) {
		this.version = version;
	}
	public String getPayMethod() {
		return payMethod;
	}
	public void setPayMethod(String payMethod) {
		this.payMethod = payMethod;
	}
	public String getStudentAddress() {
		return studentAddress;
	}
	public void setStudentAddress(String studentAddress) {
		this.studentAddress = studentAddress;
	}
	public String getStudentCompany() {
		return studentCompany;
	}
	public void setStudentCompany(String studentCompany) {
		this.studentCompany = studentCompany;
	}
	public String getStudentPhone() {
		return studentPhone;
	}
	public void setStudentPhone(String studentPhone) {
		this.studentPhone = studentPhone;
	}
	public boolean isStudentSex() {
		return studentSex;
	}
	public void setStudentSex(boolean studentSex) {
		this.studentSex = studentSex;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public PrivilegeStrategy getPrivilegeStrategy() {
		return privilegeStrategy;
	}
	public void setPrivilegeStrategy(PrivilegeStrategy privilegeStrategy) {
		this.privilegeStrategy = privilegeStrategy;
	}
	
	public static final String NOT_PAY="未确认到款";
	public static final String HAVE_PAYED="已确认到款";
	public static final String PASSED="已完成授课";

	public static final String NOT_PAY_COLOR="CC3333";
	public static final String HAVE_PAYED_COLOR="3333CC";
	public static final String PASSED_COLOR="9999FF";
	
	public String checkStatus(){
		if(this.getStatus()==null){
			return NOT_PAY;
		}else{
			if(this.getStatus().equals(NOT_PAY)||this.getStatus().equals(HAVE_PAYED)||this.getStatus().equals(PASSED)){
				return this.getStatus();
			}else{
				return NOT_PAY;
			}
		}
	}

	public String checkColor(){
		if(this.getStatus()==null){
			return NOT_PAY_COLOR;
		}
		if(this.getStatus().equals(NOT_PAY)){
			return NOT_PAY_COLOR;
		}
		if(this.getStatus().equals(HAVE_PAYED)){
			return HAVE_PAYED_COLOR;
		}
		if(this.getStatus().equals(PASSED)){
			return PASSED_COLOR;
		}
		return NOT_PAY_COLOR;
	}
	
	public float getActualPrice(){
		float actualPrice = -1;
		if(this.getArrangedCourse()!=null){
			if(this.getArrangedCourse().getTrainingSubject()!=null){
				int price = this.getArrangedCourse().getTrainingSubject().getPrice();
				if(this.getPrivilegeStrategy()!=null){
					actualPrice=(this.getPrivilegeStrategy().getDiscount()*price)/100;
				}else{
					actualPrice = price;
				}
			}
		}
		return actualPrice;
	}
	public Date getSubscribeDate() {
		return subscribeDate;
	}
	public void setSubscribeDate(Date subscribeDate) {
		this.subscribeDate = subscribeDate;
	}
}
